import {
    http,
    defaultSuccess,
    defaultError
} from "@/plugins/axios";

export default {
    /**
     * 角色列表
     * @param page
     * @param success
     * @param error
     */
    list(page, success = defaultSuccess, error = defaultError) {
        http.get("/role/list", {params: {page: page}}).then(success).catch(error)
    },
    /**
     * 搜索
     * @param key
     * @param page
     * @param success
     * @param error
     */
    search(key, page, success = defaultSuccess, error = defaultError) {
        http.get("/role/search", {params: {key: key, page: page}}).then(success).catch(error)
    },
    /**
     * 查询指定角色权限
     * @param id
     * @param success
     * @param error
     */
    getRolePermissions(id, success = defaultSuccess, error = defaultError) {
        http.get("/role/permission/" + id).then(success).catch(error)
    },
    /**
     * 角色授权
     * @param param
     * @param success
     * @param error
     */
    grantPermission(param, success = defaultSuccess, error = defaultError) {
        http.post("/role/grant", param).then(success).catch(error)
    },
    /**
     * 添加角色
     * @param param
     * @param success
     * @param error
     */
    save(param, success = defaultSuccess, error = defaultError) {
        http.post("/role/add", param).then(success).catch(error)
    },
    /**
     * 更新角色信息
     * @param param
     * @param success
     * @param error
     */
    update(param, success = defaultSuccess, error = defaultError) {
        http.post("/role/edit", param).then(success).catch(error)
    },
    /**
     * 详情
     * @param id
     * @param success
     * @param error
     */
    detail(id,success = defaultSuccess, error = defaultError){
        http.get("/role/"+id).then(success).catch(error)
    },
    /**
     * 刪除
     * @param id
     * @param success
     * @param error
     */
    delete(id, success = defaultSuccess, error = defaultError) {
        http.get("/role/delete/" + id).then(success).catch(error)
    },
    /**
     * 查询指定分组角色
     * @param group
     * @param success
     * @param error
     */
    groupRoles(group, success = defaultSuccess, error = defaultError) {
        http.get("/role/group/roles/" + group).then(success).catch(error)
    },
    /**
     * 查询多个分组角色
     * @param group
     * @param success
     * @param error
     */
    groupsRoles(groups, success = defaultSuccess, error = defaultError) {
        http.get("/role/groups/roles/", {params: {groups: groups}}).then(success).catch(error)
    }
}